package com.ruan.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.ruan.dto.AddOrderDto;
import com.ruan.entity.Order;
import com.ruan.entity.R;
import com.ruan.query.OrderQuery;
import com.ruan.service.OrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * @ClassName:OrdersController
 * @Author:阮昇
 * @Description:
 * @Datetime: 2023/9/23 0:00
 **/
@RestController
@RequestMapping("/order")
@Api(tags = "商品相关接口")
public class OrderController {

    @Autowired
    private OrderService orderService;

    @ApiOperation(value = "查询商品")
    @ApiImplicitParam(name = "orderQuery", value = "订单对象", required = true, dataType = "OrderQuery")
    @PostMapping("/queryOrders")
    public R<IPage<Order>> queryOrders(@RequestBody OrderQuery orderQuery){
        return orderService.queryOrders(orderQuery);
    }

    @ApiOperation(value = "获取商品详情")
    @ApiImplicitParam(name = "orderId", value = "订单id", required = true, dataType = "Integer")
    @GetMapping("/getOrderDetails")
    public R<Order> getOrderDetails(Integer orderId){
        return orderService.getOrderDetails(orderId);
    }

    @ApiOperation(value = "获取商品热销榜")
    @ApiImplicitParam(name = "limit", value = "限制条数", required = true, dataType = "Integer")
    @GetMapping("/getHotGoodsByLimit")
    public R<List<Order>> getHotGoodsByLimit(Integer limit){
        return orderService.getHotGoodsByLimit(limit);
    }

    @ApiOperation(value = "上传商品图片")
    @ApiImplicitParam(name = "file", value = "文件", required = true, dataType = "MultipartFile")
    @RequestMapping("/uploadOrderPicture")
    @PreAuthorize("hasAuthority('uploadOrderPicture')")
    public R<String> uploadOrderPicture(MultipartFile file){
        return orderService.uploadOrderPicture(file);
    }

    @ApiOperation(value = "添加商品")
    @ApiImplicitParam(name = "addOrderDto",value = "添加商品数据", required = true, dataType = "AddOrderDto")
    @PostMapping("/addOrder")
    @PreAuthorize("hasAuthority('addOrder')")
    public R<Void> addOrder(@RequestBody AddOrderDto addOrderDto){
        return orderService.addOrder(addOrderDto);
    }

    @ApiOperation(value = "分页，模糊查询供商品列表")
    @ApiImplicitParam(name = "page", value = "商品查询类", required = true, dataType = "OrderQuery")
    @PostMapping("/queryGoodsList")
    public R<IPage<Order>> queryGoodsList(@RequestBody OrderQuery orderQuery){
        return orderService.queryOrdersList(orderQuery);
    }

    @ApiOperation(value = "分页，模糊查询采购商品列表")
    @ApiImplicitParam(name = "orderQuery", value = "商品查询类", required = true, dataType = "OrderQuery")
    @PostMapping("/queryPurchaseList")
    public R<IPage<Order>> queryPurchaseList(@RequestBody OrderQuery orderQuery){
        return orderService.queryPurchaseList(orderQuery);
    }


}
